﻿using ProjScan.ScanRule.Attr;
using UnityEditor;
using UnityEngine;

namespace ProjScan.ScanRule.EditorSettings
{
    [GlobalEditorSettingRuleAttr]
    internal class Editor_BuildIcons : GlobalEditorSettingRule
    {
        public override void Run()
        {
            result = true;
            if (EditorUserBuildSettings.activeBuildTarget == BuildTarget.Android)
            {
                Texture2D[] iconsForTargetGroup = PlayerSettings.GetIconsForTargetGroup(BuildTargetGroup.Android);
                int num;
                if (iconsForTargetGroup != null && iconsForTargetGroup.Length != 0)
                {
                    Texture[] array = iconsForTargetGroup;
                    Texture[] array2;
                    num = (TexturesAllNull(array2 = array) ? 1 : 0);
                }
                else
                {
                    num = 1;
                }

                if (num != 0)
                {
                    result = false;
                }
            }
            else if (EditorUserBuildSettings.activeBuildTarget == BuildTarget.iOS)
            {
                Texture2D[] iconsForTargetGroup2 = PlayerSettings.GetIconsForTargetGroup(BuildTargetGroup.iOS);
                int num2;
                if (iconsForTargetGroup2 != null && iconsForTargetGroup2.Length != 0)
                {
                    Texture[] array = iconsForTargetGroup2;
                    Texture[] array2;
                    num2 = (TexturesAllNull(array2 = array) ? 1 : 0);
                }
                else
                {
                    num2 = 1;
                }

                if (num2 != 0)
                {
                    result = false;
                }
            }
        }

        private bool TexturesAllNull(Texture[] textures)
        {
            for (int i = 0; i < textures.Length; i++)
            {
                if (textures[i] != null)
                {
                    return false;
                }
            }

            return true;
        }
    }
}